//
//  DBObjectMap.m
//  EFExtend
//
//  Created by mac on 15/4/20.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "DBObjectMap.h"


@interface DBObjectMap ()

@end

@implementation DBObjectMap

- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            
        }
    }
}

//- (NSMutableDictionary*)builtFlags{
//    
//    static dispatch_once_t once;
//    static NSMutableDictionary *_builtFlags=nil;
//    dispatch_once( &once, ^{ _builtFlags = [[NSMutableDictionary alloc] init]; } );
//    return _builtFlags;
//}
//
//- (void)buildTableFor:(Class)clazz untilRootClass:(Class)rootClass
//{
//    NSString * className = [clazz description];
//    NSNumber * builtFlag = [self.builtFlags objectForKey:className];
//    if ( builtFlag && builtFlag.boolValue )
//        return;
//    
//    // Step1, map relation between property and field
//    
//    [clazz mapRelation];
//    
//    // Step2, create table
//    
//    [NSObject DB].TABLE( clazz.tableName );
//    [NSObject DB].FIELD( clazz.activePrimaryKey, @"INTEGER" ).UNIQUE().PRIMARY_KEY();
//    
//    if ( [clazz usingAutoIncrement] )
//    {
//        [NSObject DB].AUTO_INREMENT();
//    }
//    
//    if ( [clazz usingJSON] )
//    {
//        [NSObject DB]
//        .TABLE( clazz.tableName )
//        .FIELD( clazz.activeJSONKey, @"TEXT" ).DEFAULT( @"" );
//    }
//    
//    NSDictionary * propertySet = clazz.activePropertySet;
//    if ( propertySet && propertySet.count )
//    {
//        for ( Class clazzType = clazz; clazzType != rootClass; )
//        {
//            unsigned int		propertyCount = 0;
//            objc_property_t *	properties = class_copyPropertyList( clazzType, &propertyCount );
//            
//            for ( NSUInteger i = 0; i < propertyCount; i++ )
//            {
//                const char *	name = property_getName(properties[i]);
//                NSString *		propertyName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
//                
//                NSMutableDictionary * property = [propertySet objectForKey:propertyName];
//                if ( property )
//                {
//                    const char *	attr = property_getAttributes(properties[i]);
//                    NSUInteger		type = [BeeTypeEncoding typeOf:attr];
//                    
//                    NSString *		field = [property objectForKey:@"field"];
//                    NSObject *		value = [property objectForKey:@"value"];
//                    
//                    if ( BeeTypeEncoding.NSNUMBER == type )
//                    {
//                        [NSObject DB].FIELD( field, @"INTEGER" );
//                    }
//                    else if ( BeeTypeEncoding.NSSTRING == type )
//                    {
//                        [NSObject DB].FIELD( field, @"TEXT" );
//                    }
//                    else if ( BeeTypeEncoding.NSDATE == type )
//                    {
//                        [NSObject DB].FIELD( field, @"TEXT" );
//                    }
//                    else if ( BeeTypeEncoding.NSDICTIONARY == type )
//                    {
//                        [NSObject DB].FIELD( field, @"TEXT" );			// save as JSON
//                    }
//                    else if ( BeeTypeEncoding.NSARRAY == type )
//                    {
//                        [NSObject DB].FIELD( field, @"TEXT" );			// save as "id,id,id" or JSON
//                    }
//                    else if ( BeeTypeEncoding.OBJECT == type )
//                    {
//                        Class fieldClass = [BeeTypeEncoding classOfAttribute:attr];
//                        if ( [fieldClass isSubclassOfClass:rootClass] )
//                        {
//                            [NSObject DB].FIELD( field, @"INTEGER" );	// save as primary ID
//                        }
//                        else
//                        {
//                            [NSObject DB].FIELD( field, @"TEXT" );		// save as JSON
//                        }
//                    }
//                    else
//                    {
//                        [NSObject DB].FIELD( field, @"INTEGER" );
//                    }
//                    
//                    if ( [clazzType usingAutoIncrementForProperty:field] )
//                    {
//                        [NSObject DB].AUTO_INREMENT();
//                    }
//                    
//                    if ( [clazzType usingUniqueForProperty:field] )
//                    {
//                        [NSObject DB].UNIQUE();
//                    }
//                    
//                    if ( value && NO == [value isKindOfClass:[BeeNonValue class]] )
//                    {
//                        [NSObject DB].DEFAULT( value );
//                    }
//                    
//                    [property setObject:[NSNumber numberWithInteger:type] forKey:@"type"];
//                }
//            }
//            
//            free( properties );
//            
//            clazzType = class_getSuperclass( clazzType );
//            if ( nil == clazzType )
//                break;
//        }
//    }
//    
//    [NSObject DB].CREATE_IF_NOT_EXISTS();
//    
//    // Step3, do migration if needed
//    
//    // TODO:
//    //	"pragma table_info(\"test\")";
//    //	"alter table \"test\" add column name";
//    
//    // Step4, create index
//    
//    [NSObject DB].TABLE( clazz.tableName ).INDEX_ON( clazz.activePrimaryKey, nil );
//    
//    [_builtFlags setObject:[NSNumber numberWithBool:YES] forKey:className];
//}

@end
